/**
 * 
 */
package hibernate.daos;

import hibernate.pojos.Users;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author jlbugarin
 * 
 */
public class UsersDaoImpl extends HibernateDaoSupport implements UsersDao {

	public UsersDaoImpl(){}
	
	
	public UsersDaoImpl(SessionFactory sessionFactory){
		setHibernateTemplate( new HibernateTemplate(sessionFactory));
	}
	
	@Override
	@Transactional
	public List listaUsuarios() {
		// TODO Auto-generated method stub
		List listaUsers = new ArrayList();
		String sql = "from Users usr";
		Query q = this.getSession().createQuery(sql);
		listaUsers = q.list();
		System.out.println("Usuarios Recuperadas :" + listaUsers.size());

		return listaUsers;
	}


	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public void guardar(Users usr) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().save(usr);
		
	}

}
